<template>
  <div class="home-container">
    <div class="hero-section">
      <div class="hero-content-fixed">
        <h1>为流浪动物提供一个温暖的家</h1>
        <p>每一个生命都值得被关爱，让我们携手为流浪动物创造更好的未来</p>
        <el-button type="primary" size="large" @click="goToAdoption">
          <i class="fas fa-heart"></i> 立即领养
        </el-button>
      </div>
      <el-carousel height="500px" motion-blur>
        <el-carousel-item v-for="(image, index) in carouselImages" :key="index">
          <div class="carousel-content" :style="{
            background: `linear-gradient(rgba(0,0,0,0.2), rgba(0,0,0,0.2)), url(${image}) center/cover`
          }">
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>

    <div class="content">
      <div class="features-section">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-card class="feature-card" shadow="hover">
              <i class="fas fa-home feature-icon"></i>
              <h3>寻找新家</h3>
              <p>为流浪动物提供温暖的家，给予它们第二次生命的机会</p>
              <el-button type="primary" text @click="goToAdoption">查看可领养动物</el-button>
            </el-card>
          </el-col>

          <el-col :span="8">
            <el-card class="feature-card" shadow="hover">
              <i class="fas fa-hand-holding-heart feature-icon"></i>
              <h3>送养服务</h3>
              <p>无法继续饲养？我们帮助您的宠物找到新的主人</p>
              <el-button type="primary" text @click="goToSurrender">申请送养</el-button>
            </el-card>
          </el-col>

          <el-col :span="8">
            <el-card class="feature-card" shadow="hover">
              <i class="fas fa-donate feature-icon"></i>
              <h3>爱心捐助</h3>
              <p>您的每一份捐助都将帮助更多流浪动物获得救助</p>
              <el-button type="primary" text @click="goToDonation">我要捐助</el-button>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <div class="recent-pets">
        <h2>最新待领养动物</h2>
        <el-row :gutter="30">
          <el-col :span="6" v-for="pet in recentPets" :key="pet.id">
            <el-card shadow="hover" class="pet-card" @click="goToPetDetail(pet.id)">
              <div class="pet-image-wrapper">
                <img :src="`/api/Petfile/${pet.image}`" class="pet-image">
                <div class="pet-image-overlay">
                  <el-button type="primary" round>了解详情</el-button>
                </div>
              </div>
              <div class="pet-info">
                <h3>{{pet.pet_name}}</h3>
                <div class="pet-tags">
                  <el-tag size="small" effect="dark">{{pet.age}}岁</el-tag>
                  <el-tag size="small" effect="dark" type="success">{{pet.gender === 'female' ? '母' : '公'}}</el-tag>
                  <el-tag size="small" effect="dark" type="warning">{{pet.petTypeName}}</el-tag>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <div class="statistics-section">
        <h2>我们的成就</h2>
        <el-row :gutter="20">
          <el-col :span="6">
            <div class="stat-card">
              <i class="fas fa-paw stat-icon"></i>
              <div class="stat-number">{{ stats.totalPets }}</div>
              <div class="stat-label">救助动物总数</div>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="stat-card">
              <i class="fas fa-home stat-icon"></i>
              <div class="stat-number">{{ stats.adoptedPets }}</div>
              <div class="stat-label">成功领养数</div>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="stat-card">
              <i class="fas fa-heart stat-icon"></i>
              <div class="stat-number">{{ stats.waitingPets }}</div>
              <div class="stat-label">等待领养中</div>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="stat-card">
              <i class="fas fa-money-bill-wave stat-icon"></i>
              <div class="stat-number">{{ stats.totalDonations }}</div>
              <div class="stat-label">累计善款(元)</div>
            </div>
          </el-col>
        </el-row>
      </div>

      <div class="testimonials-section">
        <h2>领养故事</h2>
        <el-row :gutter="20">
          <el-col :span="8" v-for="(testimonial, index) in testimonials" :key="index">
            <el-card class="testimonial-card" shadow="hover">
              <img :src="testimonial.image" class="testimonial-image">
              <h3>{{ testimonial.name }}</h3>
              <p class="testimonial-text">{{ testimonial.content }}</p>
              <div class="testimonial-date">{{ testimonial.date }}</div>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import request from '@/utils/request'

const router = useRouter()
const recentPets = ref([])

const stats = ref({
    totalPets: 0,
    adoptedPets: 0,
    waitingPets: 0,
    totalDonations: 0
})

const testimonials = ref([
    {
        name: '小王和旺财',
        content: '领养旺财是我做过最正确的决定，它给我的生活带来了无限欢乐。',
        image: '/src/assets/indeximg/dog.png',
        date: '2023-05-15'
    },
    {
        name: '李女士和咪咪',
        content: '感谢平台让我遇见了咪咪，它现在是我家不可或缺的一员。',
      image: '/src/assets/indeximg/cat.png',
        date: '2023-06-20'
    },
    {
        name: '张先生和球球',
        content: '领养改变了球球的命运，也让我的家庭更加温暖。',
      image: '/src/assets/indeximg/qiuqiu.png',
        date: '2023-07-10'
    }
])

const carouselImages = ref([
    '/src/assets/banner/banner1.jpg',
    '/src/assets/banner/banner2.jpg', 
    '/src/assets/banner/banner3.jpg',
    '/src/assets/banner/banner4.png'
])

const goToAdoption = () => {
    router.push('/front/adoption')
}

const goToDonation = () => {
    router.push('/front/donation')
}

const goToSurrender = () => {
    router.push('/front/surrender')
}

const goToPetDetail = (id) => {
    router.push(`/front/pet/${id}`)
}

const getRecentPets = async () => {
    try {
        const res = await request({
            url: '/pet/petSearch',
            method: 'get',
            params: {
                pageNum: 1,
                pageSize: 4,
                status: 'available'
            }
        })
        recentPets.value = res.data.list
    } catch (error) {
        console.error('获取最新待领养动物失败:', error)
    }
}

const getStatistics = async () => {
  try {
    const [petsRes, availablePetsRes, donationStats] = await Promise.all([
      request.get('/pet/getAllPets'),
      request.get('/pet/petSearch', {
        params: {
          status: 'available',
          pageNum: 1,
          pageSize: 999999
        }
      }),
      request.get('/donation/statistics')
    ])

    const totalPets = petsRes.data.length
    const waitingPets = availablePetsRes.data.list.length
    const adoptedPets = totalPets - waitingPets
    const totalDonations = donationStats.data.totalAmount || 0

    stats.value = {
      totalPets,
      adoptedPets,
      waitingPets,
      totalDonations
    }
  } catch (error) {
    console.error('获取统计数据失败:', error)
  }
}

onMounted(async () => {
    await Promise.all([
      getRecentPets(),
      getStatistics()
    ])
})
</script>
<style scoped>
.home-container {
  padding: 0;
  min-height: 100vh;
  background-color: #f5f7fa;
}

.hero-section {
  position: relative;
  height: 500px;
  overflow: hidden;
}

.hero-content-fixed {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  max-width: 800px;
  padding: 0 20px;
  text-align: center;
  color: white;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
  animation: fadeInUp 1s ease-out;
}

.hero-content-fixed h1 {
  font-size: 3.8em;
  margin-bottom: 20px;
  font-weight: 800;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.hero-content-fixed p {
  font-size: 1.6em;
  margin-bottom: 35px;
  line-height: 1.8;
  font-weight: 300;
}

.hero-content-fixed .el-button {
  padding: 15px 35px;
  font-size: 1.2em;
  border-radius: 30px;
  transition: all 0.3s ease;
}

.hero-content-fixed .el-button:hover {
  transform: scale(1.1);
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.carousel-content {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.5s ease;
  animation: zoomIn 20s infinite alternate;
}

.content {
  padding: 80px 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.features-section {
  margin-bottom: 100px;
}

.feature-card {
  text-align: center;
  padding: 40px 30px;
  border-radius: 20px;
  transition: all 0.4s ease;
  height: 100%;
  background: linear-gradient(145deg, #ffffff, #f5f5f5);
  border: none;
}

.feature-card:hover {
  transform: translateY(-15px) scale(1.03);
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.feature-icon {
  font-size: 4em;
  color: #409EFF;
  margin-bottom: 30px;
  transition: all 0.3s ease;
}

.feature-card:hover .feature-icon {
  transform: scale(1.2);
  color: #66b1ff;
}

.feature-card h3 {
  margin: 25px 0;
  font-size: 2em;
  color: #2c3e50;
  font-weight: 700;
}

.feature-card p {
  color: #5c6b7f;
  margin-bottom: 30px;
  line-height: 1.8;
  font-size: 1.2em;
}

.recent-pets {
  margin-bottom: 100px;
}

.recent-pets h2 {
  text-align: center;
  margin-bottom: 50px;
  font-size: 3em;
}

.pet-card {
  border-radius: 20px;
  overflow: hidden;
  transition: all 0.4s ease;
  background: white;
  border: none;
  cursor: pointer;
}

.pet-card:hover {
  transform: translateY(-15px);
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.pet-image-wrapper {
  position: relative;
  overflow: hidden;
  height: 280px;
}

.pet-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.6s ease;
}

.pet-image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: all 0.4s ease;
}

.pet-card:hover .pet-image {
  transform: scale(1.15);
}

.pet-card:hover .pet-image-overlay {
  opacity: 1;
}

.pet-info {
  padding: 25px;
  text-align: center;
}

.pet-info h3 {
  margin: 0 0 20px;
  font-size: 1.6em;
  color: #2c3e50;
  font-weight: 700;
}

.pet-tags {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.pet-tags .el-tag {
  margin: 0;
  padding: 0 15px;
  height: 28px;
  line-height: 28px;
  font-size: 0.9em;
  border-radius: 14px;
}

.statistics-section {
  margin: 100px 0;
  text-align: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e7eb 100%);
  padding: 80px 0;
  border-radius: 30px;
}

.stat-card {
  padding: 50px 30px;
  background: white;
  border-radius: 25px;
  transition: all 0.4s ease;
  box-shadow: 0 10px 20px rgba(0,0,0,0.08);
}

.stat-card:hover {
  transform: translateY(-15px) scale(1.05);
  box-shadow: 0 25px 50px rgba(0,0,0,0.15);
}

.stat-icon {
  font-size: 3.5em;
  color: #409EFF;
  margin-bottom: 25px;
  transition: all 0.3s ease;
}

.stat-card:hover .stat-icon {
  transform: scale(1.2);
  color: #66b1ff;
}

.stat-number {
  font-size: 3em;
  font-weight: 800;
  color: #2c3e50;
  margin: 15px 0;
  background: linear-gradient(45deg, #409EFF, #66b1ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  color: #5c6b7f;
  margin-top: 20px;
  font-size: 1.3em;
  font-weight: 500;
}

.testimonials-section {
  margin: 100px 0;
  text-align: center;
}

.testimonial-card {
  padding: 40px;
  height: 100%;
  border-radius: 25px;
  transition: all 0.4s ease;
  background: linear-gradient(145deg, #ffffff, #f5f5f5);
  border: none;
}

.testimonial-card:hover {
  transform: translateY(-15px) scale(1.03);
  box-shadow: 0 25px 50px rgba(0,0,0,0.15);
}

.testimonial-image {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 30px;
  border: 6px solid #409EFF;
  transition: all 0.4s ease;
  box-shadow: 0 10px 20px rgba(64,158,255,0.2);
}

.testimonial-card:hover .testimonial-image {
  transform: scale(1.15);
  border-color: #66b1ff;
}

.testimonial-text {
  color: #5c6b7f;
  margin: 25px 0;
  line-height: 2;
  font-size: 1.2em;
  font-style: italic;
}

.testimonial-date {
  color: #909399;
  font-size: 1.1em;
  margin-top: 20px;
  font-weight: 500;
}

h2 {
  font-size: 3em;
  color: #2c3e50;
  margin-bottom: 60px;
  font-weight: 800;
  position: relative;
  padding-bottom: 20px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

h2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 4px;
  background: linear-gradient(45deg, #409EFF, #66b1ff);
  border-radius: 2px;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate(-50%, 20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

@keyframes zoomIn {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.1);
  }
}

@media (max-width: 768px) {
  .hero-content-fixed h1 {
    font-size: 2.8em;
  }
  
  .hero-content-fixed p {
    font-size: 1.3em;
  }
  
  .content {
    padding: 60px 15px;
  }
  
  .feature-card,
  .pet-card,
  .stat-card,
  .testimonial-card {
    margin-bottom: 30px;
  }

  h2 {
    font-size: 2.5em;
  }
}

@media (max-width: 480px) {
  .hero-content-fixed h1 {
    font-size: 2.2em;
  }

  .hero-content-fixed p {
    font-size: 1.1em;
  }

  .content {
    padding: 40px 10px;
  }

  h2 {
    font-size: 2em;
  }
}
</style>